package com.dy.system.controller;

import com.dy.basic.util.AjaxResult;
import com.dy.basic.util.PageList;
import com.dy.system.anno.LogAnno;
import com.dy.system.domain.SystemDictionaryType;
import com.dy.system.query.SystemQuery;
import com.dy.system.service.SystemTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/sysType")
public class SystemTypeController {

    @Autowired
    private SystemTypeService systemTypeService;

    /**
     * 查询所有的信息
     */
    @GetMapping
    public List<SystemDictionaryType> findAll(){
        return systemTypeService.findAll();
    }

    /**
     * 根据id查询用户的信息
     */

    /**
     * 修改或者添加
     */
    @PutMapping
    @LogAnno(des = "这是修改或者新增方法")
    public AjaxResult UpOrAdd(@RequestBody SystemDictionaryType systemDictionaryType){
            if (systemDictionaryType.getId() == null){
                systemTypeService.add(systemDictionaryType);
            } else {
                systemTypeService.update(systemDictionaryType);
            }
            return AjaxResult.me().success();
    }

    /**
     * 删除
     */
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
            systemTypeService.delete(id);
            return AjaxResult.me().success();
    }

    /**
     * 批量删除
     */
    @PatchMapping
    public AjaxResult deleteAll(@RequestBody List<Long> ids){
            systemTypeService.deleteAll(ids);
            return AjaxResult.me().success();
    }

    /**
     * 分页查询
     */
    @PostMapping
    public PageList<SystemDictionaryType> queryByPage(@RequestBody SystemQuery query){
        return systemTypeService.queryByPage(query);
    }

}
